from datetime import datetime

from passlib.apps import custom_app_context as pwd_context

from app import db


# 博文
class Blog(db.Model):
    __tablename__ = 'zimu_blog'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '博文表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    id = db.Column(db.Integer, db.Sequence('zimu_blog_seq'), primary_key=True)
    title = db.Column(db.String(20), comment='标题')
    content = db.Column(db.Text, comment='内容')
    createTime = db.Column(db.DateTime, default=datetime.now(), comment='发布时间')
    readingVolume = db.Column(db.Integer, comment='阅读量', default=0)
    categoryid = db.Column(db.Integer, db.ForeignKey('zimu_catgeory.id'), comment='分类ID')
    imgSrc = db.Column(db.String(150), comment='图片地址')
    # 评论列表
    replyList = db.relationship('Reply', backref='replyFromBlog', cascade="all, delete, delete-orphan",order_by="Reply.createtime")


# 文章分类表
class Category(db.Model):
    __tablename__ = 'zimu_catgeory'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '文章分类表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    id = db.Column(db.Integer, db.Sequence('zimu_catgeory_seq'), primary_key=True)
    name = db.Column(db.String(20), comment='分类名')
    # 博文列表
    blogList = db.relationship('Blog', backref='categoryInfo', cascade="all, delete, delete-orphan",order_by="Blog.createTime")


# 照片
class Photos(db.Model):
    __tablename__ = 'zimu_photos'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '相册表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    id = db.Column(db.Integer, db.Sequence('zimu_photos_seq'), primary_key=True)
    imgSrc = db.Column(db.String(150), unique=True, comment='图片地址')
    imgName = db.Column(db.String(50), comment='图片描述')
    createTime = db.Column(db.DateTime, default=datetime.now(), comment='发布时间')


# 评论表
class Reply(db.Model):
    # 表的名字:
    __tablename__ = 'zimu_reply'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '评论表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    # 表的结构:
    id = db.Column(db.Integer, db.Sequence('zimu_reply_seq'), primary_key=True)
    blogid = db.Column(db.Integer, db.ForeignKey('zimu_blog.id'), comment='博文ID')
    content = db.Column(db.Text, comment='内容')
    createtime = db.Column(db.DateTime, default=datetime.now(), comment='发布时间')
    state = db.Column(db.Boolean, comment='是否处理', default=False)
    replycontent = db.Column(db.Text, comment='回复内容')
    email = db.Column(db.String(100), comment='email', unique=True, nullable=False)
    nickname = db.Column(db.String(100), comment='昵称', nullable=False)


# 留言表
class Message(db.Model):
    # 表的名字:
    __tablename__ = 'zimu_message'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '留言表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    # 表的结构:
    Id = db.Column(db.Integer, db.Sequence('zimu_message_seq'), primary_key=True)
    content = db.Column(db.Text, comment='内容')
    createTime = db.Column(db.DateTime, default=datetime.now(), comment='发布时间')
    email = db.Column(db.String(100), comment='email', unique=True, nullable=False)
    nickname = db.Column(db.String(100), comment='昵称', nullable=False)
    state = db.Column(db.Boolean, comment='是否处理', default=False)
    replyContent = db.Column(db.Text, comment='回复内容', default=None)


# 日志表
class Log(db.Model):
    # 表的名字
    __tablename__ = 'zimu_log'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '日志表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    # 表的结构
    id = db.Column(db.Integer, db.Sequence('zimu_log_seq'), primary_key=True)
    ip = db.Column(db.String(20), comment='ip地址')
    createtime = db.Column(db.DateTime, default=datetime.now(), comment='来访时间')
    path = db.Column(db.String(100), comment='访问地址')
    parm = db.Column(db.String(255), comment='参数')
    state = db.Column(db.String(255), comment='状态')
    platform = db.Column(db.String(20), comment='操作系统')
    browser = db.Column(db.String(20), comment='浏览器')
    ipaddress = db.Column(db.String(20), comment='归属地')
    country = db.Column(db.String(50), default=None, comment='国家')
    operators = db.Column(db.String(50), default=None, comment='运营商')


# 情书
class loveText(db.Model):
    # 表的名字
    __tablename__ = 'love_text'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '情话', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    # 表的结构
    id = db.Column(db.Integer, db.Sequence('love_text_seq'), primary_key=True)
    content = db.Column(db.String(255), comment='内容')
    praisePoints = db.Column(db.Integer, comment='点赞数', default=0)
    createTime = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')

# 系统表
class System(db.Model):
    # 表的名字
    __tablename__ = 'zimu_system'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '系统表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    # 表的结构
    id = db.Column(db.Integer, db.Sequence('zimu_system_seq'), primary_key=True)
    key = db.Column(db.String(100), comment='关键词Key')
    value = db.Column(db.String(150), comment='关键词Value',default="")
    content = db.Column(db.String(20), comment='字段描述')
    type = db.Column(db.String(20), comment='字段类型')

# 技能表
class Tool(db.Model):
    # 表的名字
    __tablename__ = 'zimu_tool'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '系统表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    # 表的结构
    id = db.Column(db.Integer, db.Sequence('zimu_tool_seq'), primary_key=True)
    toolImgSrc = db.Column(db.String(100), comment='技能图')
    percent = db.Column(db.Integer, comment='百分比')


# 疫情详情表
class Details(db.Model):
    # 表的名字
    __tablename__ = 'zimu_details'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '疫情详情表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    # update_time,province,city,confirm,confirm_add,heal,dead
    id = db.Column(db.Integer, db.Sequence('zimu_details_seq'), primary_key=True)
    update_time = db.Column(db.DateTime, comment='更新时间')
    province = db.Column(db.String(50), comment='省份')
    city = db.Column(db.String(50), comment='城市')
    confirm = db.Column(db.String(50), comment='确诊')
    confirm_add = db.Column(db.String(50), comment='确诊新增')
    heal = db.Column(db.String(50), comment='治愈')
    dead = db.Column(db.String(50), comment='死亡')


# 疫情历史表
class History(db.Model):
    # 表的名字
    __tablename__ = 'zimu_history'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '疫情历史表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    id = db.Column(db.Integer, db.Sequence('zimu_history_seq'), primary_key=True)
    ds = db.Column(db.Date, comment='更新时间')
    confirm = db.Column(db.String(50), comment='确诊')
    confirm_add = db.Column(db.String(50), comment='确诊新增')
    suspect = db.Column(db.String(50), comment='疑似')
    suspect_add = db.Column(db.String(50), comment='疑似新增')
    heal = db.Column(db.String(50), comment='治愈')
    heal_add = db.Column(db.String(50), comment='治愈新增')
    dead = db.Column(db.String(50), comment='死亡')
    dead_add = db.Column(db.String(50), comment='死亡新增')

# csdn blog
class CsdnBlog(db.Model):
    __tablename__ = 'csdn_blog'
    __bind_key__ = 'csdn'

    id = db.Column(db.Integer, db.Sequence('csdb_blog_id_seq'), primary_key=True)
    title = db.Column(db.String(255), comment='标题')
    content = db.Column(db.Text, comment='内容')
    href = db.Column(db.String(255), comment='链接')
    create_time = db.Column(db.Date, comment='爬取时间')
    nickname = db.Column(db.String(50), comment='作者名')
    time = db.Column(db.Date, comment='发布时间')
    tag = db.Column(db.String(50), comment='标签')

# yuwuzheng news
class YuwuzhengNews(db.Model):
    __tablename__ = 'ywz_news'
    __bind_key__ = 'yuwuzheng'

    id = db.Column(db.Integer, db.Sequence('ywz_news_Id_seq'), primary_key=True, autoincrement=True)
    title = db.Column(db.String(100))
    content = db.Column(db.Text)
    href = db.Column(db.String(50))
    pubtime_date = db.Column(db.Date)
    pubtime_time = db.Column(db.Time)
    status = db.Column(db.Integer, default=1)

# 友情链接
class FriendHref(db.Model):
    # 表的名字
    __tablename__ = 'zimu_friend_href'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '友情链接表', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    id = db.Column(db.Integer, db.Sequence('zimu_friend_href_seq'), primary_key=True)
    title = db.Column(db.String(50), comment='标题')
    href = db.Column(db.String(50), comment='链接')
    createTime = db.Column(db.DateTime, comment='创建时间', default=datetime.now())
    upgradeTime = db.Column(db.DateTime, comment='更新时间', default=datetime.now())

# 网站地图
class SiteMap(db.Model):
    # 表名字
    __tablename__ = 'zimu_sitemap'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '网站地图', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    Id = db.Column(db.Integer, db.Sequence('zimu_sitemap_seq'), primary_key=True)
    loc = db.Column(db.String(50), comment='地址')
    priority = db.Column(db.String(50), comment='优先权')
    lastmod = db.Column(db.Date, comment='更新时间', default=datetime.now())
    changefreq = db.Column(db.String(50), comment='更新频率')

# 推广页面
class Promotion(db.Model):
    # 表名字
    __tablename__='zimu_promotion'
    __bind_key__ = 'blog'
    __table_args__ = ({'comment': '推广页面', 'mysql_collate': 'utf8mb4_general_ci'})  # 添加表注释

    Id = db.Column(db.Integer, db.Sequence('zimu_promotion_seq'), primary_key=True)
    name = db.Column(db.String(50), comment='名字')
    title = db.Column(db.String(50), comment='标题')
    by_friend = db.Column(db.String(50), comment='好友利益')
    by_me = db.Column(db.String(50), comment='我的奖励')
    href = db.Column(db.String(100), comment='推广链接')
    startTime = db.Column(db.Date(), comment='开始时间')
    endTime = db.Column(db.Date(), comment='结束时间')
